package cn.echoparrot.domain.service;

import lombok.Data;
import org.springframework.ai.document.Document;
import org.springframework.ai.embedding.BatchingStrategy;

import java.util.ArrayList;
import java.util.List;

@Data
public class DocumentCountBatchStrategy implements BatchingStrategy {

    // 后续再考虑从配置文件读取
    private int batchMaxSize = 10;

    @Override
    public List<List<Document>> batch(List<Document> documents) {
        // 按batchMaxSize 将 List 切分成多个 List
        List<List<Document>> batches = new ArrayList<>();
        
        for (int i = 0; i < documents.size(); i += batchMaxSize) {
            int end = Math.min(i + batchMaxSize, documents.size());
            batches.add(documents.subList(i, end));
        }
        
        return batches;
    }
}